<?php
include_once("function/config.php");
include('function/fnc.php');

$new_date = strtotime ( '+1 month' , strtotime ( $dateto ) ) ;
$new_date = date ( 'Y-m-j' , $new_date );
if($dateto != NULL && $new_date==$datefrom) {
		header("Location: buy.php");
}

$mdpass = mysql_fetch_array(mysql_query("SELECT MDPass FROM admin"));
$passlock = mysql_fetch_array(mysql_query("SELECT Passlock FROM admin"));
if($passlock['Passlock'] == NULL OR $mdpass['MDPass'] != $passlock['Passlock']) {
		header("Location: error.php");
}

if(isset($_POST['login'])){

	$userName= trim($_POST['userName']);
	$userPassword = trim($_POST['userPassword']);
	
	if($userName == NULL OR $userPassword == NULL){

		$final_report.="Please complete both fields";
	}else{

		$check_user_data = mysql_query("SELECT * FROM `members` WHERE `userName` = '".$userName."'") or die(mysql_error());
		if(mysql_num_rows($check_user_data) == 0){

			$final_report.="This username does not exist";
		}else{

			$get_user_data = mysql_fetch_array($check_user_data);
			if($get_user_data['userPassword'] == $userPassword){

				$start_idsess = $_SESSION['userName'] = "".$get_user_data['userName']."";
				$start_passsess = $_SESSION['userPassword'] = "".$get_user_data['userPassword']."";
				$final_report.="<meta http-equiv='Refresh' content='0; URL=home.php'/>";
			}
		}
	}
}
	

// Check IP Quality Score 
if(IPQC == "ON") {
	
	$key = IPQCKey; // Account API Key
	$ip = $_SERVER['REMOTE_ADDR']; // IP to Lookup
	$result = file_get_contents('http://www.ipqualityscore.com/api/ip_lookup.php?KEY='.$key.'&IP='.$ip);
	if($result == 1) {
	header("Location: oops.php");
	}
}


// Check ProxStop status
if(ProxStop == "ON") {
	callProxstop();
}

include("function/includes.php");

if(isset($_POST['register'])){

	$oldusername = $_POST['username'];
	$username = mysql_real_escape_string($oldusername);
	$safeusername = addslashes($username);
	$oldpassword = $_POST['password'];
	$password = mysql_real_escape_string($oldpassword);
	$email = $_POST['email'];
	$points = $bonuspoints;
	$memip = $_SERVER['REMOTE_ADDR'];
	$memport = $_SERVER['REMOTE_PORT'];
	$leadedOffers=0;

	if(isset($_GET['join'])){

		$referral_ID = $_GET['join'];}
		$date = date("Y-m-d H:i:s");

		if($username == NULL OR $password == NULL OR $email == NULL){

			$final_report2.= "Please complete all fields";
		}else{

			$check_ip = mysql_query("SELECT * FROM `members` WHERE `ip` = '$memip'");   
			if(mysql_num_rows($check_ip) != 0){

				$final_report2.="The Ip address is already in use!";  
			}else{

				$check_members = mysql_query("SELECT * FROM `members` WHERE `userName` = '$username'");

				if(mysql_num_rows($check_members) != 0){

					$final_report2.="The username is already in use!";  
				}else{ 

					if(strlen($username) <= 5 || strlen($username) >= 33){
					
						$final_report2.="Your username must be between 6 and 32 characters";
					}else{ 

						if(strlen($password) <= 5 || strlen($password) >= 33){
							
							$final_report2.="Your password must be between 6 and 32 characters";
						}else{
							
							$create_member = mysql_query("INSERT INTO `members` (`id`,`userName`, `userPassword`, `email`, `points`,`leadedOffers`,`referralId`, `ip`,`port`, `date`,`requester`,`status`) 
							VALUES('','$username','$password','$email','$points', '$leadedOffers','$referral_ID', '$memip','$memport','$date','','')"); 
							//$final_report2.="Thank you!";

							$_SESSION['userName'] = $username;
							$_SESSION['userPassword'] = $password;
							$final_report2.="<meta http-equiv='Refresh' content='0; URL=wall.php?name=SuperSonicAds'/>";

						}
					}
				}
			}
		}
	}

?>

<?php
	if(isset($_SESSION['userName'])
		&& isset($_SESSION['userPassword'])){

	header("Location: home.php");
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="single, slider, free templates, website templates, CSS, HTML" />
<meta name="description" content="Single Slider is a free CSS template provided by templatemo.com" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.5.2.js" ></script>
<script type="text/javascript" src="js/kwicks-1.5.1.pack.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<div id="wrapper">
	<div id="header">
		<div id="xlogo">
		</div>
	</div>
	<div id="content">
		<div class="register">	
			<h3>Register Form</h3>
			<form action="" method="post">
				<label for="username" class="label">Username</label> <input type="text" name="username" class="txt" value="<?php if(isset($username)){echo $username; } ?>" /><br>
				<label for="password" class="label">Password</label> <input type="password" name="password" class="txt" value="<?php if(isset($password)){echo $password; } ?>" /><br>
				<label for="email" class="label">Email</label> <input type="text" name="email" class="txt" value="<?php if(isset($email)){echo $email; } ?>" /><br>
				<input type="submit" name="register" value="" class="btn"/>
			</form>
			<?php if(isset($final_report2) && $final_report2 !=""){?>
			<p class="error">
				<?php echo $final_report2; ?>
			</p>
			<?php } ?>
		</div>
		<div class="line"></div>
		<div class="register">
			<h3>Login Form</h3>
			<form action="" method="post">
                <label for="username" class="label">Username</label> <input name="userName" type="text" title="username" class="txt" value="" onclick="if ( value == 'Username' ) { value = ''; }"/>
                <label for="password" class="label">Password</label> <input name="userPassword" type="password" class="txt" title="password" value="" onclick="if ( value == 'Password' ) { value = ''; }"/>
                <input type="Submit" name="login" class="btn" value="" tabindex="3" />
			</form>
			<?php if(isset($final_report2) && $final_report2 !=""){?>
			<p class="error">
				<?php echo $final_report2; ?>
			</p>
			<?php } ?>
		</div>
	</div>
	<div id="footer">
		<div id="navv">
			<h2><ul class="nav">
				<li><a href="">Help</a></li>
				<li><a href="">Contact Us</a></li>
			</ul></h2>
		</div>
	</div>
</div> <!-- END of templatemo_wrapper -->
</body>
</html>